update platform 6

Documentation Version for Comments and Changes

You are invited to make any changes...add any comments.

Changes will `eventually` be merged into the offical documentation.

Leave any commnents here...

...

... back to index page OE documentation



ifdef/end ifdef) with UNIX and the symbol that is that of the specific OS will be followed.

We assume that the environment is always run from some kind of CLI in two routines: The routine has_console always returns 0, and maybe_any_key never waits for key input.

Interfacing with C Code

On Windows and Unix it is possible to interface Euphoria code with C code. Your Euphoria program can call C routines and read and write C variables. C routines can even call ("callback") your Euphoria routines. The C code must reside in a dynamic link or shared library. By interfacing with dynamic link libraries and shared libraries, you can access the full programming interface on these systems.

Using the Euphoria to C Translator, you can translate Euphoria routines to C, and compile them into a shared library file. You can pass Euphoria atoms and sequences to these compiled Euphoria routines, and receive Euphoria data as a result. Translated/compiled routines typically run much faster than interpreted routines. For more information, see the Translator.

Calling C Functions

To call a C function in a shared library file you must perform the following steps:

  1. Open the shared library file that contains the C function by calling open_dll.
  2. Define the C function, by calling define_c_func or define_c_proc. This tells Euphoria the number and type of the arguments as well as the type of value returned.
    Euphoria currently supports all C integer and pointer types as arguments and return values. It also supports floating-point arguments and return values (C double type). It is currently not possible to pass C structures by value or receive a structure as a function result, although you can certainly pass a pointer to a structure and get a pointer to a structure as a return value. Passing C structures by value is rarely required for operating system calls.
    Euphoria also supports all forms of Euphoria data - atoms and arbitrarily-complex sequences, as arguments to translated/compiled Euphoria routines.
  3. Call the C function by calling c_func or c_proc
include dll.e 
 
atom user32 
integer LoadIcon, icon 
 
user32 = open_dll("user32.dll") 
 
-- The name of the routine in user32.dll is "LoadIconA". 
-- It takes a pointer and an 32-bit integers as arguments, 
-- and it returns a 32-bit integer. 
LoadIcon = define_c_func(user32, "LoadIconA", {C_POINTER, C_INT}, C_INT) 
 
icon = c_func(LoadIcon, {NULL, IDI_APPLICATION}) 

See c_func, c_proc, define_c_func, define_c_proc, open_dll

See demo\win32 or demo/linux for example programs.

On Windows there is more than one C calling convention. The Windows API routines all use the __stdcall convention. Most C compilers however have __cdecl as their default. __cdecl allows for variable numbers of arguments to be passed. Euphoria assumes __stdcall, but if you need to call a C routine that uses __cdecl, you can put a '+' sign at the start of the routine name in define_c_proc and define_c_func. In the example above, you would have "+LoadIconA", instead of "LoadIconA".

You can examine a dll file by right-clicking on it, and choosing "QuickView" (if it's on your system). You will see a list of all the C

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu